#!/usr/bin/env bash
#=============================================================================
#     FileName: setup.sh
#         Desc: setup for lim
#      License: GPL
#       Author: Steve Lemuel
#        Email: wlemuel@hotmail.com
#      Version: 0.0.1
#   LastChange: 2020-11-14 09:45:19
#    CreatedAt: 2016-07-16 12:14:58
#=============================================================================

if which apt-get >/dev/null; then
    sudo apt-get install -y vim ctags astyle python-setuptools git python-dev
elif which yum >/dev/null;then
    sudo yum install -y gcc vim git ctags astyle python-setuptools python-devel
fi

if [ `uname` == 'Darwin' ] && which brew >/dev/null;then
    echo ">> You are using HomeBrew tool!"
    brew install vim ctags git astyle
fi

echo ">> Backup your old vim."
CUR_DATE=$(date "+%Y-%m-%d")
[ -e ~/.vimrc ] && mv -f ~/.vimrc ~/.vimrc_old_$CUR_DATE
[ -e ~/.vim ] && mv -f ~/.vim ~/.vim_old_$CUR_DATE

echo ">> Start to clone the lim, please wait for a while."
cd ~ && git clone git@gitee.com:wlemuel/lim.git ~/.vim

# cp ~/.vim/config/python.vimrc ~/.vimrc
ln -s ~/.vim/config/general.vimrc ~/.vimrc

# echo ">> Installing the Vundle (vim plugin manager)."
# git clone https://github.com/gmarik/Vundle.vim  ~/.vim/bundle/Vundle.vim

echo "Start to install plugins." > ~/.vim/lim.log
echo "[ I WILL EXCIT AUTOMATICALLY AFTER FINISHED. ]" >> ~/.vim/lim.log
echo "Please wait for a while." >> ~/.vim/lim.log

# cleanup log
trap "rm -rf ~/.vim/lim.log && exit 0" 2

vim ~/.vim/lim.log -c "PlugInstall" -c "q" -c "q"
rm -f ~/.vim/lim.log

echo ">> Setup finished! Please enjoy the *LIM*. ＼（＾-＾）／"
